<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-form ref="form" :model="product_plan" :rules="rules" label-width="100px" id="mvcfm">
      <div class="form-unit">
        <span class="mvc-title-left"> 增加生产计划 </span>
      </div>
      <div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="标题" prop="plan_title">
              <el-input v-model="product_plan.plan_title" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="生产编码" prop="plan_barcode">
              <el-input v-model="s_ecode.bar" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="产品名称" prop="">
              {{product_plan.product_id}}
              <el-button @click="popProductSelection1('','product_id')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="生产工艺" prop="">
              {{product_plan.category_id}}
              <el-button @click="popProduceFlowSelect('','category_id')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="计划负责人" prop="">
              {{product_plan.plan_charge}}
              <el-button @click="popSelectionOfficerCurrency('','plan_charge')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="产品数量" prop="product_num">
              <el-input v-model="product_plan.product_num" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品单位" prop="">
              <el-input v-model="empty" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="开始时间" prop="begin_time">
              <el-date-picker v-model="product_plan.begin_time" type="date" style='width:100%' value-format="yyyy-MM-dd" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交货时间" prop="com_time">
              <el-date-picker v-model="product_plan.com_time" type="date" style='width:100%' value-format="yyyy-MM-dd" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="计划说明" prop="plan_explain">
              <el-input type="textarea" v-model="product_plan.plan_explain" ttparea=350></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input type="textarea" v-model="product_plan.remark" ttparea=350></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item>
              <el-button @click="increaseProductionPlanSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
              <el-button @click="gotoPage('/mes/produce/ProductionPlanStatistical?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>返回</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>
    <el-dialog :visible.sync="ProductSelection1Visible" append-to-body>
      <ProductSelection1 v-if="ProductSelection1Visible" ref="ProductSelection1" :popparams="popparams"> </ProductSelection1>
    </el-dialog>
    <el-dialog :visible.sync="ProduceFlowSelectVisible" append-to-body>
      <ProduceFlowSelect v-if="ProduceFlowSelectVisible" ref="ProduceFlowSelect" :popparams="popparams"> </ProduceFlowSelect>
    </el-dialog>
    <el-dialog :visible.sync="SelectionOfficerCurrencyVisible" append-to-body>
      <SelectionOfficerCurrency v-if="SelectionOfficerCurrencyVisible" ref="SelectionOfficerCurrency" :popparams="popparams"> </SelectionOfficerCurrency>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import ProductSelection1 from "@/views/mes/supplychainmana/ProductSelection1";
  import ProduceFlowSelect from "@/views/mes/main/ProduceFlowSelect";
  import SelectionOfficerCurrency from "@/views/mes/autooffice/SelectionOfficerCurrency";
  export default {
    name: 'IncreaseProductionPlan',
    components: {
      ProductSelection1,
      ProduceFlowSelect,
      SelectionOfficerCurrency,
    },
    props: ['popparams'],
    data() {
      return {
        ProductSelection1Visible: false,
        ProductSelection1Value: null,
        ProductSelection1Desc: null,
        ProduceFlowSelectVisible: false,
        ProduceFlowSelectValue: null,
        ProduceFlowSelectDesc: null,
        SelectionOfficerCurrencyVisible: false,
        SelectionOfficerCurrencyValue: null,
        SelectionOfficerCurrencyDesc: null,
        vueparams: this.getVUEParams(""),
        product_plan: {
          plan_title: null,
          plan_barcode: null,
          product_id: null,
          category_id: null,
          plan_charge: null,
          product_num: null,
          begin_time: null,
          com_time: null,
          plan_explain: null,
          remark: null,
        },
        loading: false,
        rules: {
          plan_title: [{
            required: true,
            message: "标题不能为空",
            trigger: 'blur',
          }],
          product_num: [{
            required: true,
            message: "产品数量不能为空",
            trigger: 'blur',
          }],
          begin_time: [{
            required: true,
            message: "开始时间不能为空",
            trigger: 'blur',
          }],
          com_time: [{
            required: true,
            message: "交货时间不能为空",
            trigger: 'blur',
          }],
        }
      }
    },
    created() {
      this.getData();
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/produce/ProductionPlanMange/increaseProductionPlan?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      increaseProductionPlanSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/mes/produce/ProductionPlanMange/increaseProductionPlanSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/mes/produce/ProductionPlanStatistical/productionPlanStatistical?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popProductSelection1(desc, value) {
        this.ProductSelection1Visible = true;
        this.ProductSelection1Desc = desc;
        this.ProductSelection1Value = value;
      },
      closeProductSelection1(value, desc) {
        this.ProductSelection1Visible = false;
        this.$set(this.product_plan, this.ProductSelection1Desc, desc);
        this.$set(this.product_plan, this.ProductSelection1Value, value);
      },
      popProduceFlowSelect(desc, value) {
        this.ProduceFlowSelectVisible = true;
        this.ProduceFlowSelectDesc = desc;
        this.ProduceFlowSelectValue = value;
      },
      closeProduceFlowSelect(value, desc) {
        this.ProduceFlowSelectVisible = false;
        this.$set(this.product_plan, this.ProduceFlowSelectDesc, desc);
        this.$set(this.product_plan, this.ProduceFlowSelectValue, value);
      },
      popSelectionOfficerCurrency(desc, value) {
        this.SelectionOfficerCurrencyVisible = true;
        this.SelectionOfficerCurrencyDesc = desc;
        this.SelectionOfficerCurrencyValue = value;
      },
      closeSelectionOfficerCurrency(value, desc) {
        this.SelectionOfficerCurrencyVisible = false;
        this.$set(this.product_plan, this.SelectionOfficerCurrencyDesc, desc);
        this.$set(this.product_plan, this.SelectionOfficerCurrencyValue, value);
      },
    },
  }
</script>
